
That begs the question how do you separate the time into seperate elements?
Making use of explode can work. Exploding where there a : so:
$parts = explode(':', '14:25:00');
This would result in an array:
[
"14",
"25",
"00",
]
To use an element you can refer to its index for example $parts[0] would contain 14
Using them by their index is fine to do but kinda messy.
I prefer to give each element a name using the list function
list($hours, $minutes, $seconds) = explode(':', '14:25:00');
When using list() passing an array to it will allow you to name each index of the array in the order listed.
Putting this into practice I like to define the null versions before using list to ensure the variables will exist.
$estimatedTime = 14:25:00;
$estimatedHour = null;
$estimatedMinute = null;
$estimatedSeconds = null;
list($estimatedHour, $estimatedMinute, $estimatedSeconds) = explode(':', $estimatedTime);
Now we have the variables that can be used in select menus:
note I'm using Blade syntax here for readability.
<select name="estimatedTime_hour">
<option value="0">Hours</option>
@foreach(range(0,23) as $hour)
<option value="{{ $hour }}" {{ old('estimatedTime_hour', $estimatedHour) == $hour ? 'selected=selected' : '' }}>{{ $hour }}</option>
@endforeach
</select>
<select name="estimatedTime_minute">
<option value="0">Minutes&l Recent Questions...
ما را در سایت Recent Questions دنبال میکنید
برچسب:
نویسنده: استخدام کار
بازدید: 84
تاريخ: سه
شنبه
25 مهر
1402 ساعت: 14:14